import 'package:elevator/widgets/group_choose_dialog/group_choose_dialog_view.dart';
import 'package:flutter/material.dart';

class GroupChooseDialogState extends State<GroupChooseDialog>{
  Function? onSaveClick;
  Function? onGroupSelectChanged;
  int selectPositionId;

  GroupChooseDialogState({this.onSaveClick, this.onGroupSelectChanged,this.selectPositionId = 0});

  @override
  Widget build(BuildContext context) {
    return Material(
        type: MaterialType.transparency,
        child:InkWell(
            onTap: ()=>Navigator.pop(context),
            child:Container(
            color: Colors.transparent,
            alignment: Alignment.topCenter,
            child:Container(
              alignment: Alignment.topCenter,
              height: 160.0,
              margin: const EdgeInsets.fromLTRB(20,60,20,0),
              decoration: const BoxDecoration(
                //背景装饰
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(4.0)),
              ),
              child: InkWell(
                onTap: ()=>debugPrint("dialog click"),
                child:Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment:CrossAxisAlignment.center,
                children: <Widget>[
                  const Padding(
                    padding: EdgeInsets.all(10),
                    child: Text("添加/删除组（Group）",style:TextStyle(fontSize: 16)),
                  ),
                  Container(
                      child: Wrap(
                        children: List<Widget>.generate(
                          5,(int index) {
                          return ChoiceChip(
                            label: Text((index + 1).toString()),
                            labelStyle: TextStyle(
                              color: selectPositionId == index ? Colors.white : Colors.black,
                            ),
                            selectedColor:Colors.blueGrey,
                            selected: selectPositionId == index,
                            onSelected: (bool selected) {
                              if(null != onGroupSelectChanged){
                                setState(() {
                                  selectPositionId = index;
                                });
                                onGroupSelectChanged!(selected,index);
                              }
                            },
                          );
                        },
                        ).toList(),
                      )
                  ),
                  Container(
                      alignment: Alignment.bottomRight,
                      padding: const EdgeInsets.fromLTRB(0, 20, 20, 0),
                      child: ElevatedButton(
                        style: ButtonStyle(
                            foregroundColor: MaterialStateProperty.all(Colors.white),
                            backgroundColor:
                            MaterialStateProperty.all(Colors.blueGrey),
                            textStyle:
                            MaterialStateProperty.all(const TextStyle(fontSize: 16)),
                            overlayColor: MaterialStateProperty.all(Colors.grey)),
                        onPressed: () {
                          if(null != onSaveClick){
                            onSaveClick!();
                            Navigator.pop(context);
                          }
                        },
                        child: const Text('保存'), //选中的颜色字体颜色
                      )
                  )

                ],
              )),
            )))
    );
  }
}
